////////////////////////////////////////////////////////////////////////////////
/// @file    main.c
/// @author  AE TEAM
/// @brief   THIS FILE PROVIDES ALL THE SYSTEM FUNCTIONS.
////////////////////////////////////////////////////////////////////////////////
/// @attention
///
/// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
/// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
/// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
/// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
/// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
/// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
///
/// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
////////////////////////////////////////////////////////////////////////////////

// Define to prevent recursive inclusion
#define _MAIN_C_

// Files includes
#include "led.h"
#include "delay.h"
#include "uart.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "los_sys.h"
#include "los_task.ph"
#include "los_memory.ph"


////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MM32_Example_Layer
/// @{

////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MAIN
/// @{

////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MAIN_Exported_Constants
/// @{


static void Led1Task(void)
{
    while(1) {
        LED3_TOGGLE();
        LED4_TOGGLE();
        LOS_TaskDelay(1000);
    }
}
static void Led2Task(void)
{
    while(1) {
        LED1_TOGGLE();
        LED2_TOGGLE();
        LOS_TaskDelay(500);
    }
}
UINT32 RX_Task_Handle;
UINT32 TX_Task_Handle;
static UINT32 AppTaskCreate(void)
{
	UINT32 uwRet = LOS_OK;
	
    TSK_INIT_PARAM_S task_init_param;	

	task_init_param.usTaskPrio = 4;
	task_init_param.pcName = "RxTask";
	task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)Led1Task;
	task_init_param.uwStackSize = 0x100;	
	uwRet = LOS_TaskCreate(&RX_Task_Handle, &task_init_param);
    if (uwRet != LOS_OK)
    {
        printf("Led1Task create failed,%X\n",uwRet);
        return uwRet;
    }
    
    task_init_param.usTaskPrio = 4;	
	task_init_param.pcName = "TxTask";
	task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)Led2Task;
	task_init_param.uwStackSize = 0x100;
	uwRet = LOS_TaskCreate(&TX_Task_Handle, &task_init_param);
    if (uwRet != LOS_OK)
    {
        printf("Led2Task create failed,%X\n",uwRet);
        return uwRet;
    } 
	return LOS_OK;
}
void HardFault_Handler(void)
{
  /* USER CODE BEGIN HardFault_IRQn 0 */

  /* USER CODE END HardFault_IRQn 0 */
  while (1)
  {
    /* USER CODE BEGIN W1_HardFault_IRQn 0 */
    /* USER CODE END W1_HardFault_IRQn 0 */
  }
  /* USER CODE BEGIN HardFault_IRQn 1 */

  /* USER CODE END HardFault_IRQn 1 */
}
////////////////////////////////////////////////////////////////////////////////
/// @brief  This function is main entrance.
/// @param  None.
/// @retval  0.
////////////////////////////////////////////////////////////////////////////////
s32 main(void)
{
    /* USER CODE BEGIN 1 */
    UINT32 uwRet = LOS_OK;
    DELAY_Init();
    LED_Init();
//    DELAY_Init();
    CONSOLE_Init(115200);
     /* USER CODE BEGIN 2 */  
      if (LOS_OK != LOS_KernelInit())	
      {
          return LOS_NOK;
      }
      uwRet = AppTaskCreate();
      if(uwRet != LOS_OK) {
          printf("LOS Creat task failed\r\n");
          //return LOS_NOK;
      }
      LOS_Start();
}


/// @}

/// @}

/// @}
